﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.UI;

namespace DigitalAmele.WebApp.Tools.MessageBox
{
    public class MessageBox
    {
        #region Constant Values

        private const string confirm = "close_progressing();alert(1);debugger;$.confirm({";
        private const string return_false = "return false;";
        private const string comma = ",";
        private const string buttons = "'buttons': {";

        #endregion

        #region Properties

        public MessageTypes MessageType { get; set; }
        public bool HasReturn { get; set; }
        //public string Title { get; set; }
        public string Message { get; set; }
        public List<BoxButton> BoxButtons { get; set; }

        #endregion

        #region Base Functions

        //private static string get_title(string title) { return "'title': '" + title + "'"; }
        private static string get_message(string msg) { return "'message': '" + msg + "'"; }
        private static string get_className(MessageTypes mt) { return "'classN': '" + mt.ToString() + "'"; }
        public static string get_bostback_action(Control c) { return "__doPostBack('" + c.UniqueID + "', '')"; }

        #endregion

        public string get_function()
        {
            StringBuilder boxHtml = new StringBuilder();
            //boxHtml.Append("$('#ModalOverlay, #ModalText').fadeOut('fast', function() {$('#ModalTextMsg').html(\"Lütfen bekleyiniz...\");");
            boxHtml.Append(confirm);
            //boxHtml.Append(get_title(Title));
            //boxHtml.Append(comma);
            boxHtml.Append(get_message(Message));
            boxHtml.Append(comma);
            boxHtml.Append(get_className(MessageType));
            boxHtml.Append(comma);
            boxHtml.Append(buttons);

            int count = BoxButtons.Count;

            foreach (BoxButton item in BoxButtons)
            {
                boxHtml.Append(item.create_button());
                if (--count > 0) boxHtml.Append(comma);
            }

            boxHtml.Append("}");
            boxHtml.Append("});");
            // boxHtml.Append("});");

            if (HasReturn) boxHtml.Append(return_false);

            return boxHtml.ToString();
        }
    }
}